package com.dh.bm.controller;

import com.dh.bm.entity.Book;
import com.dh.bm.entity.vo.BookVo;
import com.dh.bm.service.BookService;
import com.dh.bm.util.DateUtil;

import java.util.List;

public class BookController {
    private BookService bookService = new BookService();

    public boolean addBook(String name, String author, int stock, int cid) {
        Book book = new Book();
        book.setName(name);
        book.setAuthor(author);
        book.setStock(stock);
        book.setCid(cid);
        book.setCreatedTime(DateUtil.getNowDate());
        book.setUpdatedTime(DateUtil.getNowDate());
        return bookService.add(book);
    }

    // 获取全部书籍
    public List<Book> queryAll() {
        return bookService.queryAll();
    }

    // 获取单个书籍
    public BookVo queryById(int id) {
        return bookService.queryById(id);
    }

    public boolean updateBookById(int id, String name, String author, int stock) {
        Book book = new Book();
        book.setBid(id);
        book.setName(name);
        book.setAuthor(author);
        book.setStock(stock);
        book.setUpdatedTime(DateUtil.getNowDate());
        return bookService.update(id, book);
    }
}
